import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";

function useTk() {
  const [isLogin, setIsLogin] = useState(false);
  const token = localStorage.getItem("token");
  const nav = useNavigate();
  useEffect(() => {
    if (token) {
      setIsLogin(true);
    } else {
      setIsLogin(false);
      nav("/login");
      alert(未登录);
    }
  });
  return { isLogin: isLogin };
}

export default useTk;
